jQuery.extend({
  getCookie : function(sName) {
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++){
      var aCrumb = aCookie[i].split("=");
      if (sName == aCrumb[0]) return decodeURIComponent(aCrumb[1]);
    }
    return '';
  },
  setCookie : function(sName, sValue, sExpires) {
    var sCookie = sName + "=" + encodeURIComponent(sValue);
    if (sExpires != null) sCookie += "; expires=" + sExpires;
    document.cookie = sCookie;
  },
  removeCookie : function(sName) {
    document.cookie = sName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
  }
});
function drop_confirm(msg, url){
    if(confirm(msg)){
        window.location = url;
    }
}

/* 显示Ajax表单 */
function ajax_form(id, title, url, width)
{
    if (!width)
    {
        width = 400;
    }
    var d = DialogManager.create(id);
    d.setTitle(title);
    d.setContents('ajax', url);
    d.setWidth(width);
    d.show('center');

    return d;
}
function go(url){
    window.location = url;
}

function change_captcha(jqObj){
    jqObj.attr('src', 'index.php?app=captcha&' + Math.round(Math.random()*10000));
}

/* 格式化金额 */
function price_format(price){
    if(typeof(PRICE_FORMAT) == 'undefined'){
        PRICE_FORMAT = '&yen;%s';
    }
    price = number_format(price, 2);

    return PRICE_FORMAT.replace('%s', price);
}

function number_format(num, ext){
    if(ext < 0){
        return num;
    }
    num = Number(num);
    if(isNaN(num)){
        num = 0;
    }
    var _str = num.toString();
    var _arr = _str.split('.');
    var _int = _arr[0];
    var _flt = _arr[1];
    if(_str.indexOf('.') == -1){
        /* 找不到小数点，则添加 */
        if(ext == 0){
            return _str;
        }
        var _tmp = '';
        for(var i = 0; i < ext; i++){
            _tmp += '0';
        }
        _str = _str + '.' + _tmp;
    }else{
        if(_flt.length == ext){
            return _str;
        }
        /* 找得到小数点，则截取 */
        if(_flt.length > ext){
            _str = _str.substr(0, _str.length - (_flt.length - ext));
            if(ext == 0){
                _str = _int;
            }
        }else{
            for(var i = 0; i < ext - _flt.length; i++){
                _str += '0';
            }
        }
    }

    return _str;
}

/* 收藏商品 */
function collect_goods(id)
{
    var url = SITE_URL + '/index.php?app=my_favorite&act=add&type=goods&ajax=1';
    $.getJSON(url, {'item_id':id}, function(data){
        alert(data.msg);
    });
}

/* 收藏商家 */
function collect_store(id)
{
    var url = SITE_URL + '/index.php?app=my_favorite&act=add&type=store&jsoncallback=?&ajax=1';
    $.getJSON(url, {'item_id':id}, function(data){
        alert(data.msg);
    });
}
/* 火狐下取本地全路径 */
function getFullPath(obj)
{
    if(obj)
    {
        //ie
        if (window.navigator.userAgent.indexOf("MSIE")>=1)
        {
            obj.select();
            if(window.navigator.userAgent.indexOf("MSIE") == 25){
            	obj.blur();
            }
            return document.selection.createRange().text;
        }
        //firefox
        else if(window.navigator.userAgent.indexOf("Firefox")>=1)
        {
            if(obj.files)
            {
                //return obj.files.item(0).getAsDataURL();
            	return window.URL.createObjectURL(obj.files.item(0)); 
            }
            return obj.value;
        }
		
        return obj.value;
    }
}


/**
 *    启动邮件队列
 *
 *    @author    Garbin
 *    @param     string req_url
 *    @return    void
 */
function sendmail(req_url)
{
    $(function(){
        var _script = document.createElement('script');
        _script.type = 'text/javascript';
        _script.src  = req_url;
        document.getElementsByTagName('head')[0].appendChild(_script);
    });
}
/* 转化JS跳转中的 ＆ */
function transform_char(str)
{
    if(str.indexOf('&'))
    {
        str = str.replace(/&/g, "%26");
    }
    return str;
}

function is_mobile(v){  
	 var a = /^1[34578]{1}\d{9}$/ ;  
	 if( v.length!=11||!v.match(a) ){  
	 return false
	 }
	 return true;
 }  

function sendSms(mobileobj,getObj,newmember,captcha)
{
			 var mobile=mobileobj.val();
			 if (mobile=="")
			 {
				alert("请输入手机号!");
				return; 
			 }
			 if (!is_mobile(mobile))
			 {
				alert("手机号填写有误");
				return; 
			 }

                var myurl="index.php?app=member&act=send_check_code&mobile="+mobile+"&captcha="+captcha;
                if (newmember==1)
			  {
                  myurl="index.php?app=member&act=send_check_code_new&mobile="+mobile+"&captcha="+captcha;
			  }
			  
			  $.get(myurl, function(result){
									
				  switch(result)
				  {
					  case "1":
						   var step = 59;
							 getObj.val(' 重新发送60 ');
							 var _res = setInterval(function()
							 {   
								 getObj.attr("disabled", true);//设置disabled属性
								getObj.val(' 重新发送'+step+' ');
								 step-=1;
								 if(step <= 0){
								 getObj.removeAttr("disabled"); //移除disabled属性
								getObj.val('重新获取验证码');
								 clearInterval(_res);//清除setInterval
								 }
							 },1000);
						  break;
					  case "0":
						 break;
					  case "3":
						 alert("手机号不存在");
						  getObj.attr("disabled", false);
						 break;
                      case "5":
                          alert("手机号已经存在！");
                          getObj.attr("disabled", false);
                          break;
					  case "4":
						 alert("请勿高频重复请求!");
						 break;
					  case "6":
						 alert("图形验证码有误");
						 break;
					  case "7":
						 alert("短时间内过多请求次数，请稍后再试!");
						 break;
					  case "9":
						 alert("非法请求");
						 break;
				  }
			  });
}

function checkPasswordSafety(Password)
{
	var arr = '"123456","000000","111111","222222","333333","444444","555555","666666","777777","888888","999999"';
	return arr.indexOf(Password)==-1;
}
